package cloudUser.controller;

import cloudEntity.dto.user.SmartPermissionInsertDTO;
import cloudEntity.entity.SmartPermissionEntity;
import cloudEntity.utils.ResultUtils;
import cloudEntity.vo.PageBeanVO;
import cloudEntity.dto.user.SmartPermissionUpdateDTO;
import cloudUser.service.SmartUserPermissionService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * @program: Smart School
 * @ClassName PermissionController
 * @description:
 * @author: 陈智博
 * @create: 2025-05-16 17:41
 * @Version 1.0
 **/
@RestController
@RequestMapping("/permission")
@Tag(name = "权限控制器")
public class PermissionController {

    @Autowired
    private SmartUserPermissionService smartUserPermissionService;

    @Operation(summary = "分页查询权限")
    @Parameters({
            @Parameter(name = "n",description = "页码",required = false),
            @Parameter(name = "s",description = "条数",required = false)
    })
    @RequestMapping(method = RequestMethod.GET,value = "/all")
    public ResultUtils GetAllPermission(@RequestParam(value = "n",required = false,defaultValue = "1") Integer pageNum,
                                        @RequestParam(value = "s",required = false,defaultValue = "5") Integer pageSize)
    {
        PageBeanVO<SmartPermissionEntity> smartPermissionEntityPageBeanVO = smartUserPermissionService.GetPermissionByPage(pageNum, pageSize);
        return ResultUtils.success(smartPermissionEntityPageBeanVO);
    }

    @Operation(summary = "新增权限")
    @Parameter(name = "smartPermissionInsertDTO",description = "新增权限DTO",required = true)
    @RequestMapping(method = RequestMethod.POST,value = "/insert")
    public ResultUtils InsertPermission(@RequestBody SmartPermissionInsertDTO smartPermissionInsertDTO)
    {
        Integer i = smartUserPermissionService.InsertPermission(smartPermissionInsertDTO);
        if(i>0)
        {
            return ResultUtils.success("新增记录成功!");
        }
        return ResultUtils.failed("新增记录失败!");
    }

    @Operation(summary = "修改权限")
    @Parameter(name = "smartPermissionUpdateDTO",description = "智慧校园权限修改DTO",required = true)
    @RequestMapping(method = RequestMethod.PUT,value = "/update")
    public ResultUtils UpdatePermission(@RequestBody SmartPermissionUpdateDTO smartPermissionUpdateDTO)
    {
        Integer i = smartUserPermissionService.UpdatePermission(smartPermissionUpdateDTO);
        if(i>0)
        {
            return ResultUtils.success("修改记录成功!");
        }
        return ResultUtils.failed("修改记录失败!");
    }

    @Operation(summary = "删除权限")
    @Parameter(name = "ids",description = "权限Ids",required = true)
    @RequestMapping(method = RequestMethod.DELETE,value = "/delete")
    public ResultUtils DeletePermission(@RequestParam("ids") Integer ids)
    {
        Integer i = smartUserPermissionService.DeletePermission(ids);
        if(i>0)
        {
            return ResultUtils.success("删除记录成功!");
        }
        return ResultUtils.failed("删除记录失败!");
    }


}
